home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / sbin / foomatic-preferred-driver < prev    next >
Text File  |  2009-09-18  |  9KB  |  348 lines

  1. #!/usr/bin/perl
  2.  
  3. # This is foomatic-preferred driver, it reads the printer database
  4. # overview and puts default driver entries (<driver>..</driver>) into
  5. # every printer's XML database entry.
  6.  
  7. use Foomatic::Defaults;
  8. use Foomatic::DB qw/get_overview/;
  9. use Data::Dumper;
  10. use strict;
  11. # Needs "get_overview" to be added to the "@EXPORT_OK" list of DB.pm!
  12.  
  13. # Read out the program name with which we were called, but discard the path
  14. $0 =~ m!/([^/]+)\s*$!;
  15. my $progname = $1;
  16. my $debug = 0;
  17.  
  18. my $db = new Foomatic::DB;
  19.  
  20. # Get the printer overview list as a Perl data structure
  21. $db->get_overview();
  22. print "DB " . Dumper($db ) if $debug;
  23.  
  24. my $printer;
  25. for $printer (@{$db->{'overview'}}) {
  26.     # Skip printers without XML file. Here we cannot set a recommended
  27.     # driver
  28.     next if $printer->{'noxmlentry'};
  29.     print "$printer->{'make'} $printer->{'model'} ($printer->{'id'})";
  30.     if ($printer->{'driver'}) { # We have already a default driver
  31.     # Check whether this driver is one which supports the printer
  32.     # If yes, this printer has a correct default driver so we do not
  33.     # need to set a new default driver
  34.     my $found = 0;
  35.     for my $d (@{$printer->{'drivers'}}) {
  36.         if ($d eq $printer->{'driver'}) {
  37.         $found = 1;
  38.         last;
  39.         }
  40.     }
  41.     if ($found) {
  42.         print " (Keeping old default driver): $printer->{'driver'}\n";
  43.         next;
  44.     } else {
  45.         print " (Default driver wrong)\n";
  46.     }
  47.     } else {
  48.     print " (No default driver defined)\n";
  49.     }
  50.     if ($printer->{'functionality'} eq 'F') {
  51.     # If the printer is a "Paperweight", do not correct the
  52.     # default driver, remove the wrong setting and skip the 
  53.     # printer
  54.     $printer->{'driver'} = "";
  55.     print ": --> Skipping \"Paperweight\"\n";
  56.     } else {
  57.     #Sort drivers appropriate to ranking list
  58.     my @sorted = sort sortdrivers @{$printer->{'drivers'}};
  59.     print ": @sorted --> $sorted[0]\n";
  60.     $printer->{'driver'} = $sorted[0];
  61.     }
  62.     open PRINTERENTRY, "< $libdir/db/source/printer/$printer->{'id'}.xml" || die "   Database entry for the printer $printer->{'make'} $printer->{'model'} ($printer->{'id'}) cannot be read!\n";
  63.     my  @printerentryfield = <PRINTERENTRY>;
  64.     close PRINTERENTRY;
  65.     
  66.     my $printerentry = join ('', @printerentryfield);
  67.     if ($printerentry =~ m!<driver>(.*)</driver>!s) {
  68.     $printerentry =~ 
  69.       s!<driver>(.+)</driver>!<driver>$printer->{'driver'}</driver>!sg;
  70.     } elsif ($printerentry =~ m=(<!\-\-unknown preferred "driver"\-\->)=s){
  71.     $printerentry =~ 
  72.       s=(<!\-\-unknown preferred "driver"\-\->)=\n  <driver>$printer->{'driver'}</driver>=sg;
  73.     } elsif ($printerentry =~ m!<unverified\s*/>!s) {
  74.     $printerentry =~
  75.       s!<unverified\s*/>!<unverified />\n  <driver>$printer->{'driver'}</driver>!sg;
  76.     } elsif ($printerentry =~ m!</functionality>!s) {
  77.     $printerentry =~
  78.       s!</functionality>!</functionality>\n  <driver>$printer->{'driver'}</driver>!sg;
  79.     } else {
  80.     $printerentry =~
  81.       s!</model>!</model>\n  <driver>$printer->{'driver'}</driver>!sg;
  82.     }
  83.     open PRINTERENTRY, "> $libdir/db/source/printer/$printer->{'id'}.xml" || die "   Database entry for the printer $printer->{'make'} $printer->{'model'} ($printer->{'id'}) cannot be written!\n";
  84.     print PRINTERENTRY $printerentry;
  85.     close PRINTERENTRY;
  86. }
  87.  
  88. exit 0;
  89.  
  90. sub sortdrivers ($$) {
  91.  
  92.     # All sorting done case-sensitive and characters which are not a letter
  93.     # or number are taken out!!
  94.  
  95.     # List of driver names in a ranking which driver should be preferred
  96.     # against other drivers.
  97.     # The terms must fit to the beginning of the line, terms which must fit
  98.     # exactly must have '\$' in the end.
  99.     my @drivers =      (
  100.             # Laser printers (except winprinters)
  101.             "epl5800", # Additional functionality for Epson
  102.             "epl2050", # Laser printers
  103.             "epl2050p",
  104.             "hl1250", # Special Brother drivers should be preferred
  105.             "hl1240", # for Brother printers
  106.                         "Postscript", # Tray selection, 1200+ dpi, color laser
  107.             "alc2000", # Epson color lasers print in color 
  108.             "alc8500", # with these drivers from Epson
  109.             "cljet5\$", # color laser PCL
  110.             "cljet5c",
  111.             "pxlcolor", # 1200 dpi color laser PCL
  112.             "pxlmono", # 1200 dpi, faster than "lj5gray"
  113.             "epl5900", # This driver has a bug, "pxlmono" works
  114.                    # correctly 
  115.             "lj5gray", # 1200 dpi
  116.             "lj5mono",
  117.             "ljet4\$", # HP laser drivers, the newer, the better
  118.             "ljet4d",
  119.             "lj4dithp",
  120.             "lj4dith\$",
  121.             "hl7x0", # Brother driver, proprietary language,
  122.                  # to prefer when there is also PCL
  123.                  # emulation
  124.             "ljet3d",
  125.             "ljet3\$",
  126.             "ljet2p",
  127.             "ljetplus",
  128.             "laserjet",
  129.             # HP PPA inkjets, when a printer is supported by one
  130.             # of these drivers, it is for sure not supported by
  131.             # any other driver.
  132.             "pnm2ppa", # color
  133.             "pbm2ppa", # bw
  134.             # Lexmark 3200, the Gutenprint support for this
  135.             # printer is broken
  136.             "lxm3200-tweaked",
  137.             "lxm3200\$",
  138.             "lxm3200c",
  139.             "lxm3200m",
  140.             "lxm3200p",
  141.             # Canon BJC-8200, these UPPs are probably better
  142.             # than Gutenprint
  143.             "bj8pa06n.upp",
  144.             "bj8oh06n.upp",
  145.             "bj8ts06n.upp",
  146.             "bj8gc12f.upp",
  147.             "bj8hg12f.upp",
  148.             "bj8pp12f.upp",
  149.             # HP and compatible inkjets
  150.             "hplip", # HP drivers, with Duplex and 1200 dpi
  151.             "cdj970", # Duplex support
  152.             "DJ", # HP drivers, but no duplex
  153.             "chp2200", # HP driver
  154.             "gutenprint-ijs", # IJS plug-in driver of Gutenprint
  155.             "gutenprint", # Tray selection on laser, best 
  156.                       # quality on inkjets (for HP HP's
  157.                       # driver is better)
  158.             "gimp-print-ijs", # Old Gimp-Print driver
  159.             "gimp-print",
  160.             "stp", # Predecessor of Gimp-Print/Gutenprint
  161.             "cdj1600", # Relatively good drivers for HP inkjets
  162.             "cdj890",  # not covered by Gutenprint or the HP
  163.             "cdj880",  # drivers
  164.             "cdj850",
  165.             "cdj670",
  166.             "pcl3", # When nothing else works ...
  167.             "hpdj", # Predecessor of pcl3
  168.             "sharp.upp", # Gets Sharp inkjets to work without
  169.                          # a lot of hassle
  170.             "cdj550\$",
  171.             "cdj550.upp",
  172.             "cdj500",
  173.             "djet500", # Somewhat old-fashioned
  174.             "deskjet",
  175.             # Canon inkjets
  176.             "s400a1.upp", # New printer, UPPs are probably 
  177.             "s400b1.upp", # better than "bjc600"/"bjc800"
  178.             "bjc800", # More flexible than the Uniprint drivers
  179.             "bjc600",
  180.             "bj200",
  181.             "bj10e",
  182.             "bjc6000a1.upp",
  183.             "bjc6000b1.upp",
  184.             "bjc610a0.upp",
  185.             "bjc610a1.upp",
  186.             "bjc610a2.upp",
  187.             "bjc610a3.upp",
  188.             "bjc610a4.upp",
  189.             "bjc610a5.upp",
  190.             "bjc610a6.upp",
  191.             "bjc610a7.upp",
  192.             "bjc610a8.upp",
  193.             "bjc610b1.upp",
  194.             "bjc610b2.upp",
  195.             "bjc610b3.upp",
  196.             "bjc610b4.upp",
  197.             "bjc610b6.upp",
  198.             "bjc610b7.upp",
  199.             "bjc610b8.upp",
  200.             # Epson inkjets
  201.             "st640ih.upp",
  202.             "st640ihg.upp",
  203.             "st640p.upp",
  204.             "st640pg.upp",
  205.             "st640pl.upp",
  206.             "st640plg.upp",
  207.             "stc640p.upp",
  208.             "Stp720p.upp",
  209.             "Stp720pl.upp",
  210.             "Stp870p.upp",
  211.             "Stp870pl.upp",
  212.             "stcolor",
  213.             "st800",
  214.             "PM760p.upp",
  215.             "PM760pl.upp",
  216.             "PM820p.upp",
  217.             "PM820pl.upp",
  218.             "Stc670p.upp",
  219.             "Stc670pl.upp",
  220.             "Stc680p.upp",
  221.             "Stc680pl.upp",
  222.             "Stc760p.upp",
  223.             "Stc760pl.upp",
  224.             "Stc777p.upp",
  225.             "Stc777pl.upp",
  226.             "stc1520h.upp",
  227.             "stc800ih.upp",
  228.             "stc800p.upp",
  229.             "stc800pl.upp",
  230.             "stc740ih.upp",
  231.             "stc740p.upp",
  232.             "stc740pl.upp",
  233.             "stc600ih.upp",
  234.             "stc600p.upp",
  235.             "stc600pl.upp",
  236.             "stc500p.upp",
  237.             "stc500ph.upp",
  238.             "stc300.upp",
  239.             "stc300bm.upp",
  240.             "stc300bl.upp",
  241.             "stc2.upp",
  242.             "stc2_h.upp",
  243.             "stc2s_h.upp",
  244.             "stc.upp",
  245.             "stc_h.upp",
  246.             "stc_l.upp",
  247.             "stcany.upp",
  248.             # Lexmark inkjets
  249.             "lz11",
  250.             "cZ11somsom",
  251.             "cZ11",
  252.             "lx5000",
  253.             "lex7000",
  254.             "lex5700",
  255.             "lx5700m",
  256.             "pbm2l7k",
  257.             # Thermo sublimation printers
  258.             "ppmtomd", # The successor of "ppmtocpva"
  259.             "ppmtocpva",
  260.             "md5k",
  261.             "md2k",
  262.             # Others
  263.             "t4693d8",
  264.             "t4693d4",
  265.             "t4693d2",
  266.             "necp2x.upp",
  267.             "necp2x6.upp",
  268.             "declj250", # More adjustable options
  269.             "lj250",
  270.             "pj", # More adjustable options
  271.             "paintjet",
  272.             "pjxl", # More adjustable options
  273.             "pjetxl",
  274.             "pjxl300",
  275.             "iwhi",
  276.             "iwlo",
  277.             "necp6",  # in most cases the NEC PinWriter P6 (+)
  278.             "epsonc", # is used without colour add-on.
  279.             "epson",
  280.             "eps9high",
  281.             "eps9mid",
  282.             "lq850",
  283.             "cjet",
  284.             "lbp8",
  285.             "oki182",
  286.             "ibmpro",
  287.             "gdi",
  288.             "pbmtozjs",
  289.             # Japanese printer drivers
  290.             "rpdl",
  291.             "pr201",
  292.             "pr150",
  293.             "picty180",
  294.             "npdl",
  295.             "ml600",
  296.             "mj8000c",
  297.             "mj700v2c",
  298.             "mj6000c",
  299.             "mj500c",
  300.             "md50Mono",
  301.             "md50Eco",
  302.             "md1xMono",
  303.             "lp2000",
  304.             "lj4dithp",
  305.             "lips4v",
  306.             "lips4",
  307.             "lips2p",
  308.             "lbp320",
  309.             "lbp310",
  310.             "jj100",
  311.             "fmpr",
  312.             "fmlbp",
  313.             "filter800_3300",
  314.             "filter800",
  315.             "filter770",
  316.             "filter760",
  317.             "escpage",
  318.             "dj505j",
  319.             "bjc880j",
  320.             "bjc800j",
  321.             "bj10vh",
  322.             "bj10v",
  323.             "bj10",
  324.             "sj48",
  325.             # Omni is in experimental state, so other drivers
  326.             # give probably better output
  327.             "omni"
  328.             );
  329.  
  330.     my $first = $_[0];
  331.     my $second = $_[1];
  332.     # The driver names to compare are absolutely equal ->
  333.     #    Bug in database ==> ignore
  334.     if ($first eq $second) {return 0};
  335.  
  336.     # Check whether they are in the @standardopts list
  337.     my $i;
  338.     for ($i = 0; $i <= $#drivers; $i++) {
  339.         my $firstinlist = ($first =~ /^$drivers[$i]/);
  340.         my $secondinlist = ($second =~ /^$drivers[$i]/);
  341.         if (($firstinlist) && (!$secondinlist)) {return -1};
  342.         if (($secondinlist) && (!$firstinlist)) {return 1};
  343.     }
  344.  
  345.     # No preference found, stop here
  346.     die "No preference found between $first and $second!\n";
  347. }
  348.